package route

import (
	"github.com/gin-gonic/gin"
	"gorm-demo/global"
	"gorm-demo/handler"
	"gorm-demo/route/middlerware"
)

func InitRoute() *gin.Engine {
	router := global.ROUTER
	//中间件
	{
		global.ROUTER.Use(middlerware.LoginIntercept())
	}
	//路由
	global.ROUTER.POST("/login", handler.Login)
	router.POST("/register", handler.Register)
	userGroup := router.Group("/user")
	roleGroup := router.Group("/role")
	{
		userGroup.GET("/permissionTree", handler.UserPermissionTree)
	}
	{
		roleGroup.GET("/list", handler.RoleList)
		roleGroup.POST("/batchSave", handler.BatchSaveRole)
		roleGroup.PUT("/update", handler.UpdateRoles)
		roleGroup.DELETE("/batchDelete/:roleIds", handler.DeleteRole)
	}
	return global.ROUTER
}
